package com.finance.cooperate.feature.reader;

import com.finance.cooperate.common.constant.Constant;
import com.finance.cooperate.common.enumerate.ScrapyAppCategoriesEnum;
import com.finance.cooperate.dao.local.cache.ScrapyCache;
import com.finance.cooperate.feature.base.ReaderImpl;
import com.finance.cooperate.feature.core.feature.FeatureDefinition;
import com.finance.cooperate.feature.dto.ScrapyAppsDTO;
import com.finance.cooperate.feature.dto.ScrapyAppsMapDTO;

import java.util.Map;

/**
 * @ClassName ScrapyAppsReader
 * @Description 爬虫信息抽取
 * @Author shen
 * @Date 2022/9/16 22:19
 * @Modify ...
 */
public class ScrapyAppsReader extends ReaderImpl {
    @Override
    public Map<String, String> read(String userId) {

        ScrapyAppsDTO info = scrapyAppsService.getInfo(userId);

        super.put(FeatureDefinition.f_scrapy_apps_android_wear_count, info.getAndroidWearCount());
        super.put(FeatureDefinition.f_scrapy_apps_art_design_count, info.getArtDesignCount());
        super.put(FeatureDefinition.f_scrapy_apps_auto_vehicles_count, info.getAutoVehiclesCount());
        super.put(FeatureDefinition.f_scrapy_apps_beauty_count, info.getBeautyCount());
        super.put(FeatureDefinition.f_scrapy_apps_books_reference_count, info.getBooksReferenceCount());
        super.put(FeatureDefinition.f_scrapy_apps_business_count, info.getBusinessCount());
        super.put(FeatureDefinition.f_scrapy_apps_communication_count, info.getCommunicationCount());
        super.put(FeatureDefinition.f_scrapy_apps_comics_count, info.getComicsCount());
        super.put(FeatureDefinition.f_scrapy_apps_dating_count, info.getDatingCount());
        super.put(FeatureDefinition.f_scrapy_apps_education_count, info.getEducationCount());
        super.put(FeatureDefinition.f_scrapy_apps_entertainment_count, info.getEntertainmentCount());
        super.put(FeatureDefinition.f_scrapy_apps_events_count, info.getEventsCount());
        super.put(FeatureDefinition.f_scrapy_apps_family_count, info.getFamilyCount());
        super.put(FeatureDefinition.f_scrapy_apps_finance_count, info.getFinanceCount());
        super.put(FeatureDefinition.f_scrapy_apps_food_count, info.getFoodCount());
        super.put(FeatureDefinition.f_scrapy_apps_games_count, info.getGamesCount());
        super.put(FeatureDefinition.f_scrapy_apps_health_count, info.getHealthCount());
        super.put(FeatureDefinition.f_scrapy_apps_house_count, info.getHouseCount());
        super.put(FeatureDefinition.f_scrapy_apps_libraries_count, info.getLibrariesCount());
        super.put(FeatureDefinition.f_scrapy_apps_lifestyle_count, info.getLifestyleCount());
        super.put(FeatureDefinition.f_scrapy_apps_maps_count, info.getMapsCount());
        super.put(FeatureDefinition.f_scrapy_apps_medical_count, info.getMedicalCount());
        super.put(FeatureDefinition.f_scrapy_apps_music_count, info.getMusicCount());
        super.put(FeatureDefinition.f_scrapy_apps_news_count, info.getNewsCount());
        super.put(FeatureDefinition.f_scrapy_apps_parenting_count, info.getParentingCount());
        super.put(FeatureDefinition.f_scrapy_apps_personalization_count, info.getPersonalizationCount());
        super.put(FeatureDefinition.f_scrapy_apps_photography_count, info.getPhotographyCount());
        super.put(FeatureDefinition.f_scrapy_apps_productivity_count, info.getProductivityCount());
        super.put(FeatureDefinition.f_scrapy_apps_shopping_count, info.getShoppingCount());
        super.put(FeatureDefinition.f_scrapy_apps_social_count, info.getSocialCount());
        super.put(FeatureDefinition.f_scrapy_apps_sports_count, info.getSportsCount());
        super.put(FeatureDefinition.f_scrapy_apps_tools_count, info.getToolsCount());
        super.put(FeatureDefinition.f_scrapy_apps_travel_count, info.getTravelCount());
        super.put(FeatureDefinition.f_scrapy_apps_video_editors_count, info.getVideoEditorsCount());
        super.put(FeatureDefinition.f_scrapy_apps_weather_count, info.getWeatherCount());
        super.put(FeatureDefinition.f_scrapy_apps_top_overall_top_50, info.getTopOverallTop50Count());
        super.put(FeatureDefinition.f_scrapy_apps_top_new_top_50, info.getTopNewTop50Count());
        super.put(FeatureDefinition.f_scrapy_apps_finance_top_100, info.getFinanceTop100Count());
        super.put(FeatureDefinition.f_scrapy_apps_finance_top_50, info.getFinanceTop50Count());
        super.put(FeatureDefinition.f_scrapy_apps_finance_top_10, info.getFinanceTop10Count());

        super.put(FeatureDefinition.f_scrapy_apps_finance_count_1w, info.getFinanceCount1W());
        super.put(FeatureDefinition.f_scrapy_apps_finance_rate, info.getFinanceRate());


        super.put(FeatureDefinition.f_scrapy_cnn_01_score, info.getAppScore01());

        // 分解详细特征
        Map<String, ScrapyAppsMapDTO> typeMap = info.getScrapyTypeMap();

        for (String code : ScrapyAppCategoriesEnum.getCodes()) {

            ScrapyAppsMapDTO dto = typeMap.getOrDefault(code, new ScrapyAppsMapDTO());

            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_is_free_avg", dto.getMonetizationIsFreeAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_is_free_sum", dto.getMonetizationIsFreeSum());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_has_iap_avg", dto.getMonetizationHasIapAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_has_iap_sum", dto.getMonetizationHasIapSum());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_has_ads_avg", dto.getMonetizationHasAdsAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_has_ads_sum", dto.getMonetizationHasAdsSum());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_price_avg", dto.getMonetizationPriceAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_price_sum", dto.getMonetizationPriceSum());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_monetization_price_non_zero_count", dto.getMonetizationPriceNonZeroCount());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_rating_stars_avg", dto.getRatingStarsAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_rating_stars_min", dto.getRatingStarsMin());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_rating_stars_max", dto.getRatingStarsMax());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_rating_count_avg", dto.getRatingCountAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_rating_count_min", dto.getRatingCountMin());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_rating_count_max", dto.getRatingCountMax());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_downloads_avg", dto.getDownloadsAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_downloads_min", dto.getDownloadsMin());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_countries_len_avg", dto.getCountriesLenAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_countries_len_min", dto.getCountriesLenMin());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_lang_len_avg", dto.getLangLenAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_lang_len_min", dto.getLangLenMin());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_lang_len_lt5", dto.getLangLenLt5());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_download_size_avg", dto.getDownloadSizeAvg());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_download_size_sum", dto.getDownloadSizeSum());
            super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_inferred_female_percent_avg", dto.getInferredFemalePercentAvg());

            Map<Integer, Integer> contentRatingValueMap = dto.getContentRatingValueMap();
            for (Integer value : ScrapyCache.getTypeContentRatingValueMapValues()) {
                super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_content_rating_value_" + value, contentRatingValueMap.getOrDefault(value, Long.valueOf(Constant.MISSING_VALUE).intValue()));
            }

            Map<Integer, Integer> inferredGenderClassificationMap = dto.getInferredGenderClassificationMap();
            for (Integer value : ScrapyCache.getTypeInferredGenderClassificationMapValues()) {
                super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_inferred_gender_" + value, inferredGenderClassificationMap.getOrDefault(value, Long.valueOf(Constant.MISSING_VALUE).intValue()));
            }

            Map<Integer, Integer> inferredAgePercentagesMap = dto.getInferredAgePercentagesMap();
            for (Integer value : ScrapyCache.getTypeInferredAgePercentagesMapValues()) {
                super.put(FeatureDefinition.f_scrapy_apps_type_.getValue() + code + "_inferred_age_" + value, inferredAgePercentagesMap.getOrDefault(value, Long.valueOf(Constant.MISSING_VALUE).intValue()));
            }

        }

        return super.getResult();
    }
}
